//
//  UIButton+extension.swift
//  SwiftWeibo
//
//  Created by 牟松 on 16/8/1.
//  Copyright © 2016年 DoNews. All rights reserved.
//

import UIKit

extension UIButton{
    
    
    
    convenience init(MS_Button title:String?,
                     titleColor: UIColor = #colorLiteral(red: 0.431372549, green: 0.431372549, blue: 0.431372549, alpha: 1),
                     selectedTitleColor: UIColor = #colorLiteral(red: 0.9960784314, green: 0.5490196078, blue: 0.1411764706, alpha: 1),
                     imageName: String? = nil,
                     selectedImageName: String? = nil,
                     backgroundImageNmae: String? = nil,
                     selectedBackgroundImageName: String? = nil,
                     fontSize: CGFloat = 17) {
        self.init()
        
        self.setTitle(title, for: .normal)
        self.setTitleColor(titleColor, for: .normal)
        self.setTitleColor(selectedTitleColor, for: .highlighted)
        
        self.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        
        if let imageName = imageName,
            let selectedImageName = selectedImageName {
            self.setImage(UIImage(named: imageName), for: .normal)
            self.setImage(UIImage(named: selectedImageName), for: .highlighted)
        }

        if let backgroundImageNmae = backgroundImageNmae,
            let selectedBackgroundImageName = selectedBackgroundImageName {
            self.setBackgroundImage(UIImage(named: backgroundImageNmae), for: .normal)
            self.setBackgroundImage(UIImage(named: selectedBackgroundImageName), for: .highlighted)
        }
        
        
        
        sizeToFit()
        
    }
}
